<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
use Session;
class CollectController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    //商品收藏添加
    public function addcollect($id)
    {
        //
        $data['user_id']   = Session::get('user')[0]['id'];
        $data['goods_id']  = $id;
        DB::table('collect')->insert($data);
        return redirect('home/collect');
    }
    //显示收藏页面
    public function showcollect()
    {
        $user = Session::get('user')[0];
        $id = Session::get('user')[0]['id'];
        $data = DB::table('collect')
              ->join('goods','goods.id','=','collect.goods_id')
              ->select('goods.*','collect.cid')
              ->where('user_id',$id)
              ->get();

        return view('home.collect_list',['coll'=>$data,'user'=>$user]);
    }
    //取消收藏
    public function delcollect($id)
    {
        DB::table('collect')->where('cid',$id)->delete();
        return redirect('home/collect');
    }
  
}
